package com.tidb.example.demo.mapper;

import com.tidb.example.demo.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author : ${user}
 * @version V1.0
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: 用户的mapper
 * @date
 */
public interface UserMapper {
      /**
       * 根据名字查询用户信息
       * @return User
       */
      @Select({"SELECT * FROM user_t WHERE uname=#{uname, jdbcType=VARCHAR}"})
      User selectByUname(@Param("uname") String uname) ;

      /**
       * 查找所有的用户信息
       * @return list
       */
      @Select({"SELECT * FROM user_t"})
      List<User> selectAll() ;

      /**
       * 插入一条用户记录
       * @param user
       * @return
       */
      @Insert({"INSERT INTO user_t(uname, gender, birthday) VALUE ( #{uname, jdbcType=VARCHAR},",
                        "#{gender, jdbcType=VARCHAR},",
                        "#{birthday, jdbcType=DATE})"
      })
      int insertOne(User user) ;

      /**
       * 根据id 更新用户信息
       * @param uid
       * @return
       */
      @Update({"UPDATE user_t SET uname=#{user.uname,jdbcType=VARCHAR}," +
                         "gender=#{user.gender, jdbcType=VARCHAR}," +
                        "birthday=#{user.birthday, jdbcType=DATE} ",
                        "WHERE uid=#{uid, jdbcType=INTEGER}"
      })
      int updateById(@Param("uid") int uid, @Param("user") User user) ;

      /**
       * 根据id 删除用户信息
       * @param uid
       * @return
       */
      @Delete({"DELETE FROM user_t WHERE uid=#{uid}"})
      int deleteById(int uid) ;

      /**
       * 批量保存
       * @param users
       * @return
       */
      int batchSave(List<User> users) ;

      /**
       * 批量删除
       * @param idList
       * @return
       */
      int batchDelete(List idList) ;

}
